package com.share.oauth2.client.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;

/**
 * @author:caifan
 * @since 2023/7/26
 */
@Configuration
public class OAuth2ClientConfig {

    @Bean
    public SecurityFilterChain authorizationClientSecurityFilterChain(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.authorizeHttpRequests(authorization -> {
            authorization.anyRequest().authenticated();
        })/*.logout(logout -> logout.logoutUrl("/logout"))
                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.ALWAYS))*/
                .oauth2Client(Customizer.withDefaults())
//                .oauth2Login();
                .oauth2Login(oauth2Login -> oauth2Login.loginPage("/oauth2/authorization/myoauth2"));
        return httpSecurity.build();
    }
}
